Repository navigation
Make a document's text searchable, and read it as soon as it lands - #78
Merged
Merged
Conversation
GAM already extracted a document's text into DocumentPage rows, but only when someone pressed "Extract text", and nothing searched those rows, so a phrase on page 74 could not be found and Video Creator had nothing to read. This closes the gap the plan recorded: - An upload queues extract_text for the formats it reads. Unconditional, like music analysis: it calls nothing and costs nothing. - Pages are indexed in a new FTS5 table, page_fts, written by extract_text and backfilled by its migration from pages already read. Their own table, since every reader of segment_fts takes a hit for a transcript segment and a second. - Pages are embedded (owner kind "page", cut to 6,000 chars so one long sheet cannot fail a batch), and a finished extraction chains the embed job. - Fusion carries a page_id beside segment_id, and a search hit names its page (page_id, page_number, page_label). The search view shows it where a timestamp goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V1geD4DSV4uaESBMUTTuRu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GAM already extracted a document's text into
DocumentPagerows, but only when someone pressed Extract text. Nothing searched those rows either, so a phrase on page 74 couldn't be found and Video Creator had nothing to read. This closes the gap recorded indocs/plan-of-attack.md.What changes
services/assets._chain_text_extractionqueuesextract_textfor the formats it can read (PDF, DOCX, PPTX, XLSX, TXT/MD/CSV). It always runs, the way music analysis does, because it calls no provider and costs nothing. Formats it can't read (.doc,.odt, …) queue nothing, so they don't leave a red row.page_fts, written byextract_text._storeand removed byfts.remove_asset. Its migration (9a3e5d7c1b24) fills it from pages already extracted, so existing documents become searchable on upgrade. Pages get their own table because every reader ofsegment_ftstreats a hit as a transcript segment with a time in seconds.page). Each page is cut toMAX_PAGE_EMBED_CHARS(6,000) before embedding, because one over-long sheet would otherwise fail the whole batch. A finished extraction queues the embed job automatically.search/hybrid.pycarriespage_idbesidesegment_id.GET /api/searchhits gainpage_id,page_numberandpage_label, and the search view shows "Page 3" where a timestamp would go.Video Creator uses this to find a document and read it through the existing
GET /api/assets/{id}/text(companion PR in davior/gvc).Testing
pytest -q: 1620 passed. New tests are intests/test_document_search.py: keyword and semantic hits with their page, the type filter, re-extraction, deletion, ownership, embedding truncation, the chain from extraction to embedding, and the migration backfill (test_migrations.py).npm test(523) andnpm run buildpass./api/search?q=irrigation&asset_type=documentreturned the hit labelled "Page 3".Deploying
This adds a migration.
entrypoint.shruns it under Docker; a bareuvicornneedsalembic upgrade head. Documents uploaded before this change and never extracted still have no text. Run Extract text (bulk works) on them once.Generated by Claude Code